<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            background: red;
            position: absolute;
            left: 0px;
            top: 0px;
        }
    </style>
</head>
<body>
    <div class="box"></div>



    <script>
        let boxEle = document.querySelector(".box");
        function move (boxEle,target,dir,cb){


        var timer = setInterval(()=>{
            let num = parseInt(getComputedStyle(boxEle,null)[dir]);
            console.log(num);
            let speed = 10*(target>num?1:-1);

            if(num  === target){
                clearInterval(timer);
                cb();

                }else{
                    boxEle.style[dir]=num +speed +"px";
                }
        },100)
    }
    move(boxEle,300,"left",function(){
        move(boxEle,300,"top",function(){
            move(boxEle,0,"left",function(){
                move(boxEle,0,"top",function(){
                    console.log('完成');
                })
            })
        })
    })




    </script>
</body>
</html>